import 'package:flutter_jojo_test/common/base/base_controller.dart';
import 'package:flutter_jojo_test/common/entity/video_entity.dart';
import 'package:flutter_jojo_test/common/utils/video_utils.dart';
import 'package:flutter_jojo_test/test.dart';
import 'package:get/get.dart';
import 'package:video_player/video_player.dart';

import 'state.dart';

class HomeLogic extends BaseController {
  final HomeState state = HomeState();
  VideoUtils videoUtils = VideoUtils();

  double height(int index) {
    if (videoUtils.dds.length <= index) {
      return 0;
    }
    if (videoUtils.dds[videoUtils.list[index]?.dataSource] == null) {
      return 0;
    }
    double a = videoUtils.dds[videoUtils.list[index]?.dataSource]!;
    return videoUtils.hasData.value ? Get.width / a : 0;
  }

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    print("HOME:onInit");
    state.data = UserVideo.fetchVideo();
    videoUtils.init(state.data, state.pageController);
  }

  @override
  void onReady() {
    // TODO: implement onReady
    super.onReady();
  }

  @override
  void onClose() {
    // TODO: implement onClose
    super.onClose();
  }
}
